package com.quectel.emp.controller.sys;


import com.quectel.business.common.util.sys.SysCodeUtils;
import com.quectel.constant.global.StringKeyValuesContainer;
import com.quectel.emp.controller.BaseController;
import com.quectel.sys.module.sys.dto.SysCodeDto;
import com.quectel.sys.module.sys.service.SysCodeService;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yangkai
 * @date 2019-08-07 09:43:48
 */
@RestController
@RequestMapping("/sys/code")
@Tag(name = "SysCodeController", description = "字典值相关api")
public class SysCodeController extends BaseController {

    @DubboReference
    private SysCodeService sysCodeService;


    @GetMapping("selectByMark")
    @Operation(summary = "根据字典键获取字典列表")
    public Response<List<SysCodeDto>> selectByMark(String mark) {
        List<SysCodeDto> sysCodeDtos = SysCodeUtils.easyToGetByMark(mark);
        return Response.<List<SysCodeDto>>ok().wrap(sysCodeDtos);
    }

    @PostMapping("selectByMarks")
    @Operation(summary = "根据多个字典键获取字典列表")
    public Response<List<StringKeyValuesContainer<SysCodeDto>>> selectByMarks(@RequestBody List<String> marks) {
        List<StringKeyValuesContainer<SysCodeDto>> result = new ArrayList<>();
        for (String mark : marks) {
            List<SysCodeDto> sysCodeDtos = SysCodeUtils.easyToGetByMark(mark);
            result.add(new StringKeyValuesContainer<SysCodeDto>(mark, sysCodeDtos));
        }
        return Response.<List<StringKeyValuesContainer<SysCodeDto>>>ok().wrap(result);
    }

    @GetMapping("selectByMarkValue")
    @Operation(summary = "根据字典键获取字典具体值获取名称等信息")
    public Response<SysCodeDto> selectByMarkValue(String mark, String value) {
        SysCodeDto sysCodeDto = sysCodeService.selectOneWithMarkValue(mark, value);
        return Response.<SysCodeDto>ok().wrap(sysCodeDto);
    }

}
